import {px2rpx} from "../../../../utils/tool";
import {simpleGet} from "../../../../utils/request";
import {getLimitGoods} from "../../../../service/goods";

Component({
    properties: {
        diy:{type:Object},
        marginBottom:{
            type:Number, value:0,
            observer(data){
                if (data){
                    this.setData({
                        _marginBottom:px2rpx(data),
                    })
                }
            }
        },
        marginX: {
            type:Number, value:0,
            observer(data){
                if (data){
                    this.setData({
                        _marginX:px2rpx(data),
                    })
                }

            }
        },
        radius:{type:String, value:'fillet'},
        colNum:{type:String, value:'col_2'},
        background:{type:String, value:'none'}
    },
    data: {
        _marginBottom:0,
        _marginX:0,
        _list:[],
    },
    lifetimes:{
        attached() {
            this.setList()
        }
    },
    methods: {
        // 获取商品
        setList(){
            const {diy} = this.data
            const {config} = diy
            if (config.source == 'auto'){   // 自动获取数据源
                const where = {
                    limit: config.num
                }
                if (config.source_type == 'goods_cate'){
                    where.cate_id = config.source_id
                }else if (config.source_type == 'goods_tag'){
                    where.tag_id = config.source_id
                }
                simpleGet("/goods/list", where).then(res => {
                    this.setData({
                        _list:res.items,
                    })
                })
            }else if(config.source == 'custom'){
                this.setData({
                    _list:diy.list
                })
            }

        }
    }
});
